<template>
  <div class="app-container">
    <div class="table_container">
      <el-table
        border
        v-loading="tableloading"
        :data="tableData"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column
          property="createTime"
          :formatter="formatterTime"
          label="时间"
          width="100"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="dayAddUser"
          label="新增用户"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalUser"
          label="注册用户"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="dayAddEquipment"
          label="新增绑定设备"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalEquipment"
          label="绑定设备"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="dayDetection"
          label="新增检测次数"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="totalDetection"
          label="检测次数"
          align="center"
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { fetchHome } from "@/api/chart";
import format from "date-format";
export default {
  data() {
    return {
      tableData: [],
      limit: 20,
      currentPage: 1
    };
  },
  created() {
    this.getHomeChartDataList();
  },
  methods: {
    formatterTime(row) {
      if (row.createTime) {
        return format("yyyy-MM-dd hh:mm:ss", new Date(row.createTime));
      } else {
        return "";
      }
    },
    async getHomeChartDataList() {
      this.tableloading = true;
      const homeChartDataListData = await fetchHome();
      this.tableData = [];
      this.tableloading = false;
      homeChartDataListData.data.forEach(item => {
        const tableData = {};
        tableData.createTime = item.createTime;
        tableData.dayAddEquipment = item.dayAddEquipment;
        tableData.dayDetection = item.dayDetection;
        tableData.dayAddUser = item.dayAddUser;
        tableData.totalEquipment = item.totalEquipment;
        tableData.totalDetection = item.totalDetection;
        tableData.totalUser = item.totalUser;
        this.tableData.push(tableData);
      });
    }
  }
};
</script>

<style lang="less">
.search-box {
  padding: 20px 0;
}
.search-span {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px;
  box-sizing: border-box;
}
</style>
